#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>

int main()
{
	int year;
	int month;
	
	while (scanf("%d%d", &year, &month))
	{
		int arr[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
		if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
		{
			arr[1] = 29;
		}
		printf("%d\n", arr[month - 1]);
	}

	return 0;
}